package cn.edu.scau.cmi.tangqingning.spring.client;

import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.context.ApplicationContext;

import cn.edu.scau.cmi.tangqingning.spring.domain.Student;
import cn.edu.scau.cmi.tangqingning.spring.util.ApplicationContextUtil;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.stage.Stage;

public class springClient extends javafx.application.Application{


	@FXML
	private TextArea teacherInf;
	@FXML
	private TextField txtStu;
	@FXML
	private void onDisplayClick(ActionEvent event){
		String stuname = txtStu.getText().trim();
		teacherInf.setText("");
		ApplicationContext applicationContext = ApplicationContextUtil.getApplicationContext();
		try {
			Student student = (Student)applicationContext.getBean("zhangsan");
			teacherInf.appendText(student.getName() + "的导师为: " + student.getTutor().getName());
		} catch (NoSuchBeanDefinitionException e) {
			// TODO: handle exception
			teacherInf.setText("没有此学生");
		}
	}
	@Override
	public void start(Stage primaryStage) throws Exception {
		// TODO Auto-generated method stub
		Parent root = FXMLLoader.load(getClass().getResource("ClientView.fxml"));
		Scene scene = new Scene(root);
		primaryStage.setScene(scene);
		primaryStage.setTitle("Spring");
		primaryStage.show();
		primaryStage.setOnCloseRequest(e->System.exit(0));
	}

	public static void main(String[] args) {
		launch(args);
	}
}
